<?php
namespace app\admin\controller;




use think\Config as ThinkConfig;

class File extends CheckLogin
{

    public function uploadOne(){
        $file = $this->request->file('file');
        if(!empty($file)){
            $posterInfo = $file->validate(['ext'=>'gif,jpg,jpeg,bmp,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($posterInfo){
                $url = ThinkConfig::get('upload_file_domain').'/uploads/'.$posterInfo->getSaveName();
                return $this->jsonSuccess('上传成功', $url);
            }else{
                return $this->jsonFail($file->getError());
            }
        }else{
            return $this->jsonFail('上传失败');
        }
    }

    public function uploadImImage(){
        $file = $this->request->file('file');
        if(!empty($file)){
            $posterInfo = $file->validate(['ext'=>'gif,jpg,jpeg,bmp,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($posterInfo){
                $url = $this->request->domain().'/uploads/'.$posterInfo->getSaveName();
                return $this->json(['code'=>0, 'data'=>['src'=>$url]]);
            }else{
                return $this->jsonFail($file->getError());
            }
        }else{
            return $this->jsonFail('上传失败');
        }
    }



}